<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('校区详情')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form class="form-horizontal m" id="form-school-edit" th:object="${teachingSchool}">
                <input name="schoolId" id="schoolId" th:field="*{schoolId}" type="hidden">
                <div class="form-group">
                    <div class="col-sm-4">
                        <label class="col-sm-4 control-label">学校名称：</label>
                        <div class="col-sm-6">
                            <div class="form-control">[[*{name}]]</div>
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <label class="col-sm-4 control-label">学校简称：</label>
                        <div class="col-sm-6">
                            <div class="form-control">[[*{shortName}]]</div>
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <label class="col-sm-4 control-label">详细地址：</label>
                        <div class="col-sm-6">
                            <div class="form-control">[[*{provinceName}]] [[*{cityName}]] [[*{address}]]</div>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-4">
                        <label class="col-sm-4 control-label">负责人：</label>
                        <div class="col-sm-6">
                            <div class="form-control">[[*{principal}]]</div>
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <label class="col-sm-4 control-label">联系人电话：</label>
                        <div class="col-sm-6">
                            <div class="form-control">[[*{principalPhone}]]</div>
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <label class="col-sm-4 control-label">加盟时间：</label>
                        <div class="col-sm-6">
                            <div class="form-control">[[${#dates.format(teachingSchool.joinTime, 'yyyy-MM-dd')}]]
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-4">
                        <label class="col-sm-4 control-label">学员数量：</label>
                        <div class="col-sm-6">
                            <div class="form-control">[[*{studentCount}]]</div>
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <label class="col-sm-4 control-label">会员数量：</label>
                        <div class="col-sm-6">
                            <div class="form-control">[[*{memberCount}]]</div>
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <label class="col-sm-4 control-label">到期时间：</label>
                        <div class="col-sm-6">
                            <div class="form-control">[[${#dates.format(teachingSchool.allottedTime,
                                'yyyy-MM-dd')}]]
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <!--            <div class="col-sm-12">-->

            <div class="tabs-container" style="padding-top: 20px;">
                <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true"> 学员信息</a>
                    </li>
                    <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">账号管理</a>
                    </li>
                    <li class=""><a data-toggle="tab" href="#tab-3" aria-expanded="false">文件夹</a>
                    </li>
                </ul>
                <div class="tab-content">
                    <div id="tab-1" class="tab-pane active">
                        <div class="panel-body">
                            <table id="bootstrap-table"></table>
                        </div>
                    </div>
                    <div id="tab-2" class="tab-pane">
                        <div class="panel-body">
                            <div class="btn-group-sm" id="account-tool-bar" role="group">
                                <a class="btn btn-success" onclick="$.operate.addTab()">
                                    <i class="fa fa-plus"></i> 新增
                                </a>
                                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()">
                                    <i class="fa fa-edit"></i> 修改
                                </a>
                                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                                    <i class="fa fa-remove"></i> 删除
                                </a>
                            </div>
                            <table id="school-account"></table>
                        </div>
                    </div>
                    <div id="tab-3" class="tab-pane">
                        <div class="panel-body">
                            <div class="btn-group-sm" id="file-tool-bar" role="group">
                                <a class="btn btn-success" onclick="$.operate.addTab()">
                                    <i class="fa fa-plus"></i> 上传文件
                                </a>
                            </div>
                            <table id="school-files"></table>
                        </div>
                    </div>
                </div>


            </div>
            <!--            </div>-->
        </div>


    </div>

</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var schoolId = [[${teachingSchool.schoolId}]];
    var editFlag = [[${@permission.hasPermi('teaching:school:edit')}]];
    var removeFlag = [[${@permission.hasPermi('teaching:school:remove')}]];
    var prefix = ctx + "teaching/school";
    var prefix_file = ctx + "teaching/file";

    var data1 = [[${@dict.getType('sys_user_sex')}]];
    var data2 = [[${@dict.getType('sys_family_ref')}]];
    var data3 = [[${@dict.getType('sys_student_status')}]];

    $(function () {
        queryStudentList();
        queryAccountList();
        queryFileList();
    });

    function queryStudentList() {
        var prefixStudent = ctx + "teaching/student";
        var options = {
            url: prefixStudent + "/list",
            createUrl: prefixStudent + "/add",
            updateUrl: prefixStudent + "/edit/{id}",
            removeUrl: prefixStudent + "/remove",
            exportUrl: prefixStudent + "/export",
            modalName: "教务学员",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            columns: [{
                checkbox: true
            },
                {
                    field: 'studentId',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'studentName',
                    title: '学生姓名',
                    formatter: function (value, row, index) {
                        return '<a href="javascript:void(0)" onclick="detail(\'' + row.studentId + '\')">' + value + '</a>';
                    }
                },
                // {
                //     title: '关系',
                //     align: "right",
                //     formatter: function (value, row, index) {
                //         return $.table.selectDictLabel(data2, row.familyRefMain) + '<br/>' + $.table.selectDictLabel(data2, row.familyRefMinor) ;
                //     }
                // },
                {
                    title: '手机号码',
                    align: "left",
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(data2, row.familyRefMain) + ' ' + row.phonenumber;
                    }
                },
                {
                    field: 'schoolName',
                    title: '所属校区'
                },
                {
                    field: 'sex',
                    title: '性别',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(data1, value);
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(data3, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.studentId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.studentId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    }

    function queryAccountList() {
        var options = {
            toolbar: "account-tool-bar",
            id: "school-account",
            url: prefix + "/accountList",
            createUrl: prefix + "/addUser/?schoolId=" + schoolId,
            updateUrl: prefix + "/editUser/{id}",
            removeUrl: prefix + "/removeUser",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "用户",
            columns: [{
                checkbox: true
            },
                {
                    field: 'userId',
                    title: '用户ID'
                },
                {
                    field: 'loginName',
                    title: '登录名称',
                    sortable: true
                },
                {
                    field: 'userName',
                    title: '用户名称'
                },
                {
                    field: 'dept.deptName',
                    title: '部门'
                },
                {
                    field: 'email',
                    title: '邮箱',
                    visible: false
                },
                {
                    field: 'phonenumber',
                    title: '手机'
                },
                {
                    title: '用户状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (row.userId != 1) {
                            var actions = [];
                            actions.push("<a class='btn btn-default btn-xs' href='javascript:void(0)' onclick='resetPwd(" + row.userId + ")'><i class='fa fa-key'></i>重置密码</a> ");
                            return actions.join('');
                        } else {
                            return "";
                        }
                    }
                }]
        };
        $.table.init(options);
    }

    function queryFileList() {
        var options = {
            toolbar: "file-tool-bar",
            id: "school-files",
            url: prefix + "/listFile",
            queryParams: {
                "tableName": "teaching_school",
                "tableKey": schoolId
            },
            createUrl: prefix + "/uploadFile?schoolId=" + schoolId,
            updateUrl: prefix_file + "/edit/{id}",
            removeUrl: prefix_file + "/remove",
            exportUrl: prefix_file + "/export",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            modalName: "文件",
            columns: [{
                checkbox: true
            },
                {
                    field: 'fileId',
                    title: '文件ID',
                    visible: false
                },
                {
                    field: 'remoteFileId',
                    title: '远程文件ID',
                    visible: false
                },
                {
                    field: 'tableNameAlias',
                    title: '模块',
                    visible: false
                },
                {
                    field: 'tableName',
                    title: '表名称',
                    visible: false
                },
                {
                    field: 'fileNameOriginal',
                    title: '文件名'
                },
                {
                    field: 'filePrevImg',
                    title: '缩略图',
                    visible: false
                },
                {
                    field: 'filePath',
                    title: '存放路径'
                },
                {
                    field: 'fileSize',
                    title: '大小(bit)',
                    visible: false
                },
                {
                    field: 'createBy',
                    title: '创建者'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.fileId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.fileId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    }

    /* 用户状态显示 */
    function statusTools(row) {
        if (row.status == 1) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.userId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.userId + '\')"></i> ';
        }
    }

    /* 用户管理-停用 */
    function disable(userId) {
        $.modal.confirm("确认要冻结用户吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"userId": userId, "status": 1});
        })
    }

    /* 用户管理启用 */
    function enable(userId) {
        $.modal.confirm("确认要解冻用户吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"userId": userId, "status": 0});
        })
    }

    /* 用户管理-重置密码 */
    function resetPwd(userId) {
        var url = prefix + '/resetPwd/' + userId;
        $.modal.open("重置密码", url, '800', '300');
    }
</script>
</body>
</html>
